﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy5_1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.Text = "立方体和圆柱体";
            this.Paint += Form1_Paint; // 绑定Paint事件
            this.Size = new Size(300, 200); // 
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;


            // ========== 绘制立方体 ==========
            // 定义颜色：Alpha=70的蓝色（ARGB：Alpha=70，R=0,G=0,B=255）
            Color cubeBackColor = Color.FromArgb(70, 0, 0, 255);
            SolidBrush cubeBackBrush = new SolidBrush(cubeBackColor);

            // 背面矩形：左上角(20,20)，宽80，高80
            Rectangle cubeBackRect = new Rectangle(20, 20, 80, 80);
            g.FillRectangle(cubeBackBrush, cubeBackRect); // 填充背面矩形
            g.DrawRectangle(Pens.Black, cubeBackRect); // 绘制背面矩形边框

            // 前面矩形：左上角(20+20, 20+20) = (40,40)，宽80，高80
            Rectangle cubeFrontRect = new Rectangle(40, 40, 80, 80);
            g.DrawRectangle(Pens.Black, cubeFrontRect); // 绘制前面矩形边框（无填充）

            // 绘制连接直线（4条）：连接背面和前面矩形的4个顶点
            g.DrawLine(Pens.Black, 20, 20, 40, 40); // 左上角
            g.DrawLine(Pens.Black, 20 + 80, 20, 40 + 80, 40); // 右上角
            g.DrawLine(Pens.Black, 20, 20 + 80, 40, 40 + 80); // 左下角
            g.DrawLine(Pens.Black, 20 + 80, 20 + 80, 40 + 80, 40 + 80); // 右下角


            // ========== 绘制圆柱体 ==========
            // 定义颜色：Alpha=70的红色（ARGB：Alpha=70，R=255,G=0,B=0）
            Color cylinderBottomColor = Color.FromArgb(70, 255, 0, 0);
            SolidBrush cylinderBottomBrush = new SolidBrush(cylinderBottomColor);

            // 顶部椭圆：外切矩形左上角(160,20)，宽90，高30
            Rectangle cylinderTopRect = new Rectangle(160, 20, 90, 30);
            g.DrawEllipse(Pens.Black, cylinderTopRect); // 绘制顶部椭圆边框

            // 底部椭圆：外切矩形左上角(160, 20+70) = (160,90)，宽90，高30
            Rectangle cylinderBottomRect = new Rectangle(160, 90, 90, 30);
            g.FillEllipse(cylinderBottomBrush, cylinderBottomRect); // 填充底部椭圆
            g.DrawEllipse(Pens.Black, cylinderBottomRect); // 绘制底部椭圆边框

            // 绘制连接直线（2条）：连接顶部和底部椭圆的左右端点
            g.DrawLine(Pens.Black, 160, 20 + 15, 160, 90 + 15); // 左端点（椭圆中心的Y坐标：20+30/2=35；90+30/2=105）
            g.DrawLine(Pens.Black, 160 + 90, 20 + 15, 160 + 90, 90 + 15); // 右端点
        }
    }
}
